export const transfStr = (name = '', ids = '', list = [], type = '', notReplyList = false) => {
  let str = '';
  list.forEach(item => {
    if (name === 'Upload' && type === 'image') {
      str += `<img src="${item.imgSrc || item.loadlink || item.filelink}"/>&#8203;`;
      // str += `<img src="${item.imgSrc || item.loadlink || item.filelink}" onclick="ecCom.WeaRichText.playImg(this)"`
      //   + ` class="formImgPlay" data-imgsrc="${item.imgSrc || item.loadlink || item.filelink}" />`;
    }
    if (name === 'Upload' && type === 'file') {
      str += `<a href='javascript:try{openReplyAcc("${item.filelink}","${item.fileid}")}catch(e){window.open("${item.filelink}")}' ` 
      		+ `unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.filename}</a>`;
      if(item.showLoad){
      	str += `&nbsp;<a unselectable='off' contenteditable='false'`
      			+ `href='javascript:try{downloadFile(\"${item.loadlink}\","${item.fileid}")}catch(e){window.open(\"${item.loadlink}\")}' `
      			+ `style='cursor:pointer;text-decoration:underline;margin-right:8px'>下载(${item.filesize})</a><br>`;
      }		
    }
    if (name === 'Browser') {
      let itemName = '';
      if(type === "152") {
        itemName = item.requestnamenewspan || item.requestname || item.name || item.showname;
      } else {
        itemName = item.name || item.showname;
      }
      str += `<a onclick='openDocumentAppLink(this,${item.id},"${type}")' href='javascript:void(0);' unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline;margin-right:8px'>${itemName}</a>&nbsp;&nbsp;&nbsp;`;
    }
  });
  return str;
};

export const transfTime = (day, time) => {
  const oldDate = new Date(`${day}T${time}`);
  const nowDate = new Date();
  const duration = nowDate.getTime() - oldDate;
  const oneDay = 24 * 3600 * 1000;
  const oneHour = 3600 * 1000;
  const oneMinute = 60000;
  const tenSecond = 10000;
  let hour = 0;
  let minute = 0;
  let second = 0;
  if (duration < tenSecond) {
    return { str: '刚刚', overtime: false };
  }
  if (duration < oneMinute) {
    second = Math.floor(duration / tenSecond);
    return { str: `${second}秒前`, overtime: false };
  }
  if (duration < oneHour) {
    minute = Math.floor(duration / oneMinute);
    return { str: `${minute}分钟前`, overtime: minute > 10 };
  }
  if (duration < oneDay) {
    hour = Math.floor(duration / oneHour);
    minute = Math.floor((duration % oneHour) / oneHour);
    return { str: `${hour}小时前`, overtime: true };
  }
  return { str: `${day} ${time}`, overtime: true };
};